package com.attunlcok.unlock.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.attunlcok.common.annotation.Log;
import com.attunlcok.common.enums.BusinessType;
import com.attunlcok.unlock.domain.AttUserInfo;
import com.attunlcok.unlock.service.IAttUserInfoService;
import com.attunlcok.common.core.controller.BaseController;
import com.attunlcok.common.core.domain.AjaxResult;
import com.attunlcok.common.utils.poi.ExcelUtil;
import com.attunlcok.common.core.page.TableDataInfo;

/**
 * ATT用户信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/unlock/AttUserInfo")
public class AttUserInfoController extends BaseController
{
    private String prefix = "unlock/AttUserInfo";

    @Autowired
    private IAttUserInfoService attUserInfoService;

    @RequiresPermissions("unlock:AttUserInfo:view")
    @GetMapping()
    public String AttUserInfo()
    {
        return prefix + "/AttUserInfo";
    }

    /**
     * 查询ATT用户信息列表
     */
    @RequiresPermissions("unlock:AttUserInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AttUserInfo attUserInfo)
    {
        startPage();
        List<AttUserInfo> list = attUserInfoService.selectAttUserInfoList(attUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出ATT用户信息列表
     */
    @RequiresPermissions("unlock:AttUserInfo:export")
    @Log(title = "ATT用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AttUserInfo attUserInfo)
    {
        List<AttUserInfo> list = attUserInfoService.selectAttUserInfoList(attUserInfo);
        ExcelUtil<AttUserInfo> util = new ExcelUtil<AttUserInfo>(AttUserInfo.class);
        return util.exportExcel(list, "ATT用户信息数据");
    }

    /**
     * 新增ATT用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ATT用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:add")
    @Log(title = "ATT用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AttUserInfo attUserInfo)
    {
        return toAjax(attUserInfoService.insertAttUserInfo(attUserInfo));
    }

    /**
     * 修改ATT用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AttUserInfo attUserInfo = attUserInfoService.selectAttUserInfoById(id);
        mmap.put("attUserInfo", attUserInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存ATT用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:edit")
    @Log(title = "ATT用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AttUserInfo attUserInfo)
    {
        return toAjax(attUserInfoService.updateAttUserInfo(attUserInfo));
    }

    /**
     * 删除ATT用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:remove")
    @Log(title = "ATT用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(attUserInfoService.deleteAttUserInfoByIds(ids));
    }

    /**
     * 批量导入用户信息
     */
    @RequiresPermissions("unlock:AttUserInfo:import")
    @Log(title = "ATT用户信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(String userData)
    {
        String operName = getLoginName();
        String message = attUserInfoService.importUserData(userData, operName);
        return success(message);
    }
}
